@include('admin.header')
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="/admin/welcome">首页</a>
        <a href="">导航管理</a>
        <a>
          <cite>导航列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-primary layui-btn-small reflash" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:38px">ဂ</i></a>
    </div>
    <div class="x-body">
      <!-- <blockquote class="layui-elem-quote">每个tr 上有两个属性 cate-id='1' 当前分类id fid='0' 父级id ,顶级分类为 0，有子分类的前面加收缩图标<i class="layui-icon x-show" status='true'>&#xe623;</i></blockquote> -->
      <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加一级导航','/admin/add_nav?parent_id=0')" ><i class="layui-icon"></i>增加</button>
      </xblock>
      <table class="layui-table layui-form">
        <thead>
          <tr>
            <th>导航名称</th>
            <th width="50">排序</th>
            <th width="280">操作</th>
        </thead>
        <tbody class="x-cate list">
            @foreach($nav as $value)
            <tr cate-id='{{$value->nav_id}}' fid='{{$value->parent_id}}' >
                <td>
                <i class="layui-icon x-show" status='true'>&#xe623;</i>
                {{$value->nav_name}}
                </td>
                <td><input type="text" class="layui-input x-sort" name="order" nid="{{$value->nav_id}}" value="{{$value->nav_ord}}"></td>
                <td class="td-manage">
                <button class="layui-btn layui-btn layui-btn-xs"  onclick="x_admin_show('编辑','/admin/edit_nav?nav_id={{$value->nav_id}}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                <button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="x_admin_show('添加二级导航','/admin/add_nav?parent_id={{$value->nav_id}}')" ><i class="layui-icon">&#xe642;</i>添加二级导航</button>
                <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'{{$value->nav_id}}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                </td>
            </tr>
                @foreach($value->son as $val)
                <tr cate-id='{{$val->nav_id}}' fid='{{$val->parent_id}}' >
                    <td>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    →{{$val->nav_name}}
                    </td>
                    <td><input type="text" class="layui-input x-sort" name="order" nid="{{$val->nav_id}}" value="{{$val->nav_ord}}"></td>
                    <td class="td-manage">
                    <button class="layui-btn layui-btn layui-btn-xs"  onclick="x_admin_show('编辑','/admin/edit_nav?nav_id={{$val->nav_id}}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                    <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'{{$val->nav_id}}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                    </td>
                </tr>
                @endforeach
            @endforeach
        </tbody>
      </table>
    </div>
    <style type="text/css">
      
    </style>
    <script>
      layui.use(['form'], function(){
        form = layui.form;
        
      });

      

      /*导航-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              // console.log(id);
              $.ajax({
                url:"/admin/todo_delnav",
                type:"get",
                data:"nav_id="+id,
                dataType:"json",
                success:function(res){
                  // console.log(res);
                  if (res.code==1) {
                    $(obj).parents("tr").remove();
                    layer.msg(res.msg,{icon:1,time:1000});
                  }
                }
              })
          });
      }
      //修改排序
      $("input[name='order']").change(function(){
        var nav_id = $(this).attr("nid");
        var nav_ord = $(this).val();
        $.ajax({
          url:"/admin/changeord",
          type:"get",
          data:"nav_id="+nav_id+"&nav_ord="+nav_ord,
          dataType:"json",
          success:function(res){
            // console.log(res);
            if (res.code==1) {
              layer.msg(res.msg,{icon:1,time:1000});
            }
          }
        })
      })
    </script>
  </body>

</html>